<template>
	<view class="container">
	<image src="../../static/result-banner.png" class="banner" mode="widthFix"></image>
	<view class="box">
		
		<image src="../../static/result-success.png" class="success-img" mode="widthFix"></image>
		<view class="text2">
			您的资料已经<text style="color: #3E5EEB;">提交成功</text>
		</view>
		<text class="text1">请前往支付宝查看后续审核结果</text>
		<view @click="clickProduct(headProducts,2)" class="btn">
			点击查看
		</view>
	</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				products: [],
				headProducts: {},
				h: 23, //时
				m: 59, //分
				s: 59, //秒
				countdown: '24:00:00', //倒计时
				timer: null, //重复执行
				productsfuchuang: [],
				bannerProducts: [],

			}
		},
		computed: {
			bannerProductsRandom() {
				if (!this.bannerProducts || this.bannerProducts.length <= 0) return;
				const index = Math.floor(Math.random() * this.bannerProducts.length)
				return this.bannerProducts[index];
			}
		},
		onLoad() {
			if (uni.getStorageSync('authorize') == true) {
				uni.setStorageSync('authorize', false)
				// #ifdef H5
				window.location.href = uni.getStorageSync('authorizeUrl')
				// #endif

				return;

			}

			this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight


			this.getProductList(2)
			this.getProductList(3)
			this.getProductList(4)
			this.getProductList(6)
			this.timer = setInterval(() => {
				this.timeCount()
			}, 1000)

			//挂载成功后给pop事件绑定一个方法
			// 如果支持 popstate （一般移动端都支持）
			if (window.history && window.history.pushState) {

				history.pushState(null, null, document.URL);
				window.addEventListener('popstate', () => {
					console.log("监听到了");
					// 往历史记录里面添加一条新的当前页面的url
					// 给 popstate 绑定一个方法用来监听页面返回

					this.$router.push({
						// name: 'index'
						path: '/pages/home/home'
					})

				}, false); //false阻止默认事件
			}

		},
		onPullDownRefresh() {

			this.getProductList(2)
			this.getProductList(3)
			this.getProductList(4)
			this.getProductList(6)
		},
		onReady() {

			// if(uni.getStorageSync('authorize') == true) {
			// 	uni.setStorageSync('authorize',false)
			// 	// #ifdef H5
			// window.location.href = "https://hht-sit.haohuit.cn/?channel=rxhapi&orderId=5611857672689770556&boothId=10262023031615036866&orderType=02&hht_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyVHlwZSI6IjAxIiwiZXhwIjoxNjc5OTk0NDQ3LCJ1c2VySWQiOiI1NjExODU3NjcyNjg5NzcwNTUzIn0.fpkV_mG1y13daRhQbXQlsT737l82kaHJQjVYFeMln0A"
			// 	// #endif
			// 	return;

			// }

		},
		methods: {
			//24小时倒计时
			timeCount() {
				--this.s;
				if (this.s < 0) {
					--this.m;
					this.s = 59;
				}
				if (this.m < 0) {
					--this.h;
					this.m = 59
				}
				if (this.h < 0) {
					this.s = 0;
					this.m = 0;
				}
				this.countdown = this.h.toString().padStart(2, 0) + ":" + this.m.toString().padStart(2, 0) + ":" + this.s
					.toString().padStart(2, 0)
			},

			open() {
				this.$refs.popup.open('center')
				uni.setStorageSync('homewindow', false)

			},
			close() {
				this.$refs.popup.close()
			},
			async getProductList(e) {
				const res = await this.$myRequest({
					url: 'api/product/list',
					method: 'post',
					data: {
						'sceneId': e
					}
				});
				//头部产品
				if (e == 2) {
					var headProductsList = res.dataList
					var num = Math.floor(Math.random() * headProductsList.length)
					// console.log(num)
					Object.assign(this.headProducts, headProductsList[num])

					var show = uni.getStorageSync('homewindow')
					// show == true && headProductsList.length > 0
					if (headProductsList.length > 0) {
						// this.clickProduct(this.headProducts, 2)
					}


				}
				//列表产品
				else if (e == 3) {
					this.products = res.dataList
					// console.log(this.products)


				} else if (e == 4) {
					this.productsfuchuang = res.dataList
				} else if (e == 6) {
					this.bannerProducts = res.dataList
				}
				uni.stopPullDownRefresh();

			},
			async clickProduct(item, dataExt) {
				// console.log(item)

				await this.saveClick(item.productId, dataExt)
				if (item.unionFlag == 1) {
					this.getldUrl(item.productId)
				} else {
					// #ifdef H5
					window.location.href = item.detailUrl
					// #endif
				}


			},
			async saveClick(s, dataExt) {
				// console.log(s)
				const res = await this.$myRequest({
					url: 'api/sys/count',
					method: 'post',
					data: {
						'dataId': s,
						'operType': '2',
						'dataExt': dataExt
					}
				});
			},
			async getldUrl(s) {
				const res = await this.$myRequest({
					url: 'api/product/unionInfo',
					method: 'post',
					data: {
						'productId': s,

					}
				});
				// #ifdef H5
				window.location.href = res.productUrl
				// #endif
			},
			productLabels(labels) {
				return labels.split('|')
			},
			unitConverter(num) {
				if (num) {
					num = num.toString().split("."); // 分隔小数点
					var arr = num[0].split("").reverse(); // 转换成字符数组并且倒序排列
					var res = [];
					for (var i = 0, len = arr.length; i < len; i++) {
						if (i % 3 === 0 && i !== 0) {
							res.push(","); // 添加分隔符
						}
						res.push(arr[i]);
					}
					res.reverse(); // 再次倒序成为正确的顺序

					if (num[1]) {
						if (num[1].length < 2) {
							// 如果有小数的话添加小数部分
							res = res.join("").concat("." + num[1] + '0');
						} else if (num[1].length > 2) {
							let data = num[1].substring(0, 2)
							// 如果有小数的话添加小数部分
							res = res.join("").concat("." + data);
						} else {
							res = res.join("").concat("." + num[1]);
						}

					} else {
						res = res.join("").concat();
					}
				} else {
					res = '0.00'
				}
				return res;
			}


		}
	}
</script>

<style scoped lang="less">
	.container{
		width: 100%;
		height: 100vh;
		.banner{
			width: 100%;
		}
		.box{
			transform: translateY(-50%);
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			background: #FFFFFF;
			box-shadow: 0px 4px 10px 0px rgba(0,0,0,0.1);
			border-radius: 20px 20px 20px 20px;
			margin: 15px;
			padding: 25px;
			.success-img{
				width: 72px;
				margin-bottom: 20px;
			}
			.text1{
				color: #414141;
				font-size: 20px;
			}
			.text2{
				color: #292929;
				font-size: 24px;
				font-weight: bold;
			}
			.btn{
				width: 83%;
				height: 50px;
				background: linear-gradient( 270deg, #828FFF 0%, #3C5DEA 100%);
				border-radius: 25px 25px 25px 25px;
				font-weight: 500;
				font-size: 18px;
				line-height: 50px;
				text-align: center;
				margin-top: 20px;
				color: #FFFFFF;
			}
		}
	}
</style>